{VERSION 6 0 "IBM INTEL NT" "6.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 1 12 255 0 0 1 2 1 2 2 1 2 0 0 0 1 }{CSTYLE "2D Comment" -1 18 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "Text" -1 201 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 203 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 204 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 205 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 206 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 207 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 208 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 209 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 210 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 211 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 212 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 213 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 214 " Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 215 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 216 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 217 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 218 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 219 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 220 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 221 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 222 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 223 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 224 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 225 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 226 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 227 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 228 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 229 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 230 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 231 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 232 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 233 "Times" 1 12 104 64 92 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 234 "Times" 1 12 104 64 92 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 235 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 236 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 237 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 238 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 239 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 240 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 241 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 242 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 243 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 244 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 245 "Times" 1 12 104 64 92 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 246 "Times" 1 12 104 64 92 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 247 "T imes" 1 12 104 64 92 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 248 "Times" 1 12 104 64 92 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 249 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 250 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 251 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 252 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 253 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 254 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 255 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 256 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 257 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 258 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 259 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 260 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 0 0 0 1 } {CSTYLE "" -1 261 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 262 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 0 0 0 1 }{CSTYLE "" -1 263 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 264 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 265 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 0 0 0 1 }{CSTYLE "" -1 266 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 267 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 268 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 269 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 270 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 271 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 272 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 273 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 0 0 0 1 }{CSTYLE "" -1 274 "Times" 1 18 0 0 0 1 1 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 275 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 276 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 277 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 278 "Courier" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 279 "Courier" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 280 "Tim es" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 281 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 0 0 0 1 }{CSTYLE "" -1 282 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 283 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 284 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 285 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 286 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 287 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 288 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 289 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 290 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 291 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 292 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 293 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 294 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 295 " Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 296 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 297 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 298 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 299 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 300 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {CSTYLE "" -1 301 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE " " -1 302 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 303 " Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 304 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 305 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 306 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" -1 307 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "" 201 345 "" 1 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }{PSTYLE "No rmal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 2 0 2 0 2 2 0 1 }{PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 2 0 2 0 2 2 0 1 }{PSTYLE "Maple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 2 0 2 0 2 2 0 1 }{PSTYLE "Norma l256" -1 201 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 2 0 2 0 2 2 0 1 }{PSTYLE "Heading 1260" -1 204 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 8 4 2 0 2 0 2 2 0 1 }{PSTYLE "Normal257" -1 209 1 {CSTYLE "" -1 -1 "Time s" 1 12 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }1 1 0 0 0 0 2 0 2 0 2 2 0 1 } {PSTYLE "No Name" -1 211 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 12 12 2 0 2 0 2 2 0 1 }{PSTYLE "No Name" -1 222 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }1 1 0 0 0 0 2 0 2 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 211 "" 0 "" {TEXT 345 9 "Lecture 5" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 32 " Deletion and undoing a deletion" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 151 "Usually \+ selecting something with the cursor and hitting the delete key will de lete things. But to delete some things I have found that I need to u se " }{TEXT 203 13 "Ctrl + Delete" }{TEXT -1 23 " (which is the same a s " }{TEXT 204 6 "Delete" }{TEXT -1 1 " " }{TEXT 205 9 "Paragraph" } {TEXT -1 20 " from the pull down " }{TEXT 206 4 "Edit" }{TEXT -1 74 " \+ menu). Then the paragraph where your cursor is located will be deleted . " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 130 "A fter deleting, cutting, or pasting something, if you change your mind before doing anything else, you can go to the top of the " }{TEXT 207 4 "Edit" }{TEXT -1 10 " menu and " }{TEXT 208 4 "undo" }{TEXT -1 2 " (" }{TEXT 209 6 "ctrl-Z" }{TEXT -1 31 ") the deletion, cut, or pa ste." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 32 "A lso note that if you click the " }{TEXT 210 16 "paragraph symbol" } {TEXT -1 193 " near the right end of the menu bar it will sometimes he lp to see what you should delete. This is especially true when dealing with text. To get back to normal click the paragraph symbol again." } }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 16 " Random numbers " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 3 "If " }{TEXT 211 1 "a" }{TEXT -1 5 " and " }{TEXT 212 1 "b" }{TEXT -1 24 " are integers, the call " } {TEXT 213 10 "rand(a..b)" }{TEXT -1 35 " creates a procedure which pro duces" }{TEXT 214 1 " " }{TEXT -1 37 "(pseudo) random integers in the \+ range" }{TEXT 215 3 " a " }{TEXT 201 2 "to" }{TEXT 216 3 " b." }{TEXT -1 117 " To call the procedure one needs to add extra parenthesizes as in the following examples. If you don't add the extra " }{TEXT 217 2 "()" }{TEXT -1 7 " after " }{TEXT 218 10 "rand(a..b)" }{TEXT -1 95 " y ou just get the description of the procedure. We will, as in the custo m, call the output of " }{TEXT 219 12 "rand(a..b)()" }{TEXT -1 3 " a \+ " }{TEXT 220 13 "random number" }{TEXT -1 219 ". But strictly speaking the numbers so produced are not really random. After all, they are \+ generated by a compute program. If you wish to learn more about such m atters I recommend that you take a look at the book The " }{TEXT 221 27 "Art of Computer Programming" }{TEXT -1 1 " " }{TEXT 222 30 "Vol 2 \+ Seminumerical Algorithms" }{TEXT -1 39 ", by Donald Knuth. See Chapte r Three, " }{TEXT 223 14 "Random Numbers" }{TEXT -1 1 "." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 47 "We now illustrate \+ the use of the Maple command " }{TEXT 224 4 "rand" }{TEXT -1 48 " to p roduce pseudo-random integers from 0 to 20:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "rand(0..20)();\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "rand(0..20)();" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 129 "If you want to use this procedure repeatedly you can give it a sh orter name. I will use f here. Sometime people use names like " } {TEXT 225 4 "dice" }{TEXT -1 4 " or " }{TEXT 226 3 "die" }{TEXT -1 14 " (singular of " }{TEXT 227 4 "dice" }{TEXT -1 3 "), " }{TEXT 228 4 "r oll" }{TEXT -1 6 ", or " }{TEXT 229 4 "flip" }{TEXT -1 66 ". But you \+ can use any name you wish. Let's just name this one f. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "f:=rand(0..20)();" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 20 "Note that each time " }{TEXT 230 4 "f ()" } {TEXT -1 56 " is executed it gives a usually different random number. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "for i from 1 to 4 do (i ,f()); end do;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 74 "Or, we can crea te a sequence of 50 random numbers from 0 to 20 as follows:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "seq(f(), i=1..50);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 37 "Let's create a sequence of 50 rand om " }{TEXT 231 4 "bits" }{TEXT -1 14 " ( 0s and 1s):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "b:=rand(0..1):\nseq(b(), i=0..50); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 87 "To get a (pseudo) random number in the interval [0,1] you might us e the following idea:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "h: =rand(0..10^6):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "for i fr om 1 to 10 do\nprint(evalf(h()/10^6));\nend do;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 67 "One can also set the seed for the random number generator by using " }{TEXT 232 9 "randomize" }{TEXT -1 20 ". With no argument, " }{TEXT 233 11 "randomi ze()" }{TEXT -1 95 " will set the seed to a number based on the system clock. With a natural number as an argument," }{TEXT 234 13 " randomi ze(r)" }{TEXT -1 43 " will set the seed to the specified number " } {TEXT 235 1 "r" }{TEXT -1 2 ". " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "r:=random ize();" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "randomize(r);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}}}{SECT 1 {PARA 3 "" 0 " " {TEXT -1 12 " Random sets" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 25 "Her e's one way to pick a " }{TEXT 236 22 "(pseudo) random subset" }{TEXT -1 73 " from the set \{1,2, ...,n\}: First we must load the combinator ics package " }{TEXT 237 8 "combinat" }{TEXT -1 67 " using the followi ng command. For more on packages see the section " }{TEXT 238 8 "Packa ges" }{TEXT -1 7 " below." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "with(combinat); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 22 "The list \+ of procedure " }{TEXT 239 3 "Chi" }{TEXT -1 2 ", " }{TEXT 240 4 "bell " }{TEXT -1 61 ", etc., are procedures that are in the combinatorics p ackage " }{TEXT 241 8 "combinat" }{TEXT -1 110 ". You may use ?Chi to see what Chi does. The Warning indicates that Chi had one meaning b efore the package " }{TEXT 242 8 "combinat" }{TEXT -1 42 " was loaded \+ and now has another meaning. \n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 25 "Set n = 5 to illustrate. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "n:=5; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 63 "We set S to be the powerset of the set of integers from 1 to n." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "S:=powerset(\{seq(i,i=1..n)\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 78 "\nLet's see how many elements are in S. ( Recall that a set with n elements has " }{XPPEDIT 18 0 "2^n;" "6#)\"\" #%\"nG" }{TEXT -1 39 " subsets. Since n = 5, we ought to get " } {XPPEDIT 18 0 "2^5 = 32;" "6#/*$\"\"#\"\"&\"#K" }{TEXT -1 1 "." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(S);" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 116 "Now we define a procedure f which will generate r andom numbers between 1 and nops(S). In this case between 1 and 32." } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "f:=rand(1..nops(S)):" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 310 "\nThere are 2^5 = 32 subsets of \+ \{1,2,3,4,5\}. The set S above contains these 32 sets. The sets in S a re the sets S[1], S[2], ..., S[32]. If we use f as just defined to get a random number i from 1 to 32. Then the corresponding set S[i] may b e considered as a random subset of \{1,2,3,4,5\}. Here are some exampl es:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "S[f()];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "S [f()];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "S[f()];" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 156 "Note that each time we execute S[f()] we get a different set. \n\nA better way to generate a random set is given in the homewo rk assignment for this lecture. " }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 31 " numboccur and convert/multiset" }}{PARA 0 "" 0 "" {TEXT -1 15 "The procedures " }{TEXT 243 9 "numboccur" }{TEXT -1 5 " and " }{TEXT 244 16 "convert/multiset" }{TEXT -1 150 " can be used to simplify the \+ type of computation made in the last lecture when counting the number \+ of times a digit appears in the first n digits of " }{XPPEDIT 18 0 "p i;" "6#%#piG" }{TEXT -1 15 ". The command " }{TEXT 245 15 "numboccur( f, x)" }{TEXT -1 34 " returns the number of times that " }{TEXT 246 1 "x" }{TEXT -1 13 " is found in " }{TEXT 247 3 "f, " }{TEXT 248 29 "whe re f may be any expression" }{TEXT 249 2 ". " }{TEXT -1 23 "Here are s ome examples:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "roll:=rand( 1..6):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 156 "We create a list of 10 0 random numbers from 1 to 6. They may be thought of as the results of 100 rolls of a die (cube with numbers 1 to 6 on the six faces)." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "L:=[seq(roll(),i=1..100)]; \+ " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "We get the number of 2's in t his sequence as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "numboccur(L,2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 62 "We get the nu mber of 1's, the number of 2's, etc., as follows:" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 88 "for i from 1 to 6 do\n print(cat(`The numbe r of `, i,`s is `,numboccur(L,i)));\nend do;\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 70 "Another example. Here the first argument to numboccu r is a polynomial." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "p:=x^ 3+3*x*y+2*x^2 + 5*x + 1;\nnumboccur(p,x);\nnumboccur(p,2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "Now we define a 3 by 3 matrix." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "A:=Matrix([[3,3,5],[1,2,3],[ 1,3,6]]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "numboccur(A,3) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 72 "A nice quick way to count the number of occurrences of ea ch symbol in a " }{TEXT 250 4 "list" }{TEXT -1 2 ", " }{TEXT 251 5 "ta ble" }{TEXT -1 4 " or " }{TEXT 252 23 "some types of algebraic" } {TEXT -1 1 " " }{TEXT 253 11 "expression " }{TEXT -1 26 " is by use of the command " }{TEXT 254 19 "convert(f,multiset)" }{TEXT -1 291 ". A \+ multiset is represented in the form [ [e[1],m[1]], ..., [e[n],m[n]] ]; it is a list of pairs where each e[i] is a value (an expression), and m[i] is its multiplicity (an integer). We could have used this comman d to count the number of times each digit appears in the first 100 dig its of " }{XPPEDIT 18 0 "pi;" "6#%#piG" }{TEXT -1 3 ". " }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 24 "Here are a few exa mples:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "L:=[x,x,y,y,x,z,z ,z,x,w,w];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "convert(L,mul tiset);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "convert(x^3*y^5* z^3,multiset);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 80 "Here we count t he number of times each digit appears in the first 100 digits of " } {XPPEDIT 18 0 "pi;" "6#%#piG" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "n:=100:\nDigits:=n:\nX:=evalf(Pi,n):\nX:=floor(1 0^(n-1)*X):\n" }{MPLTEXT 1 0 23 "X:=convert(X,base, 10);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "LL:=convert(X,multiset);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 19 "Using this we have:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 141 "for i from 1 to 10 do\nd:=LL[i][1] :\ncount:=LL[i][2]:\nprintf(\"The digit %d appears %2d times in the fi rst 100 digits of %s \\n\",d,count, \"Pi\");\n" }{MPLTEXT 1 0 7 "end d o:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 9 " Packages" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 83 "E xecuting the following command loads a lot of procedures for doing lin ear algebra." }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "with(LinearAlgebra);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 255 13 "LinearAlgebra" }{TEXT -1 35 " is an example of what is called a " }{TEXT 256 7 "package" } {TEXT -1 126 " in Maple. A package is a collection of commands that m ust be loaded before they can be used. Other examples of packages are \+ " }{TEXT 257 67 "numtheory, combinat, groups, logic, orthopoly, geome try, finance, " }{TEXT -1 4 "and " }{TEXT 258 6 "plots." }{TEXT -1 1 " " }{TEXT 259 1 " " }{TEXT 201 20 "Execute the command " }{MPLTEXT 1 0 14 "?index,package" }{TEXT 201 4 " to " }{TEXT -1 133 "obtain a list of all available Maple packages. You may click on the name of the pac kage to get a list of procedures in that package. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 148 "To browse the commands i n the LinearAlgebra package execute the following command and the scro ll down and click on any procedure that interests you." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "?LinearAlgebra" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 205 "We will illustrate the use of the LinearAlgebra p ackage in a section later in this lecture. So you may delay exploring \+ it for now. The purpose of this section is just to make you aware of t he concept of a " }{TEXT 260 13 "Maple package" }{TEXT -1 1 "." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 261 21 " For future reference:" }{TEXT -1 177 " For information about writing \+ your own packages, you may execute the following command. But this is \+ not something I would recommend until you have more experience with Ma ple. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "?module/package" } }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 20 " Arrays and matrices" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 96 " In Maple an ar ray is a type of indexed variable. The subscripts each must run thru a specified " }{TEXT 262 8 "integers" }{TEXT -1 130 ". Arrays come in \+ different dimensions: 1-dimensional, 2-dimensional, 3-dimensional, etc . Here are examples. Execute each in turn." }}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 83 "We \+ define first a 1-dimensional array A with indices -3, -2, - 1, 0, 1, \+ 2, 3, 4. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "A:=array(-3.. 4);\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 26 "To assign the value 10 t o " }{XPPEDIT 18 0 "A[-3];" "6#&%\"AG6#,$\"\"$!\"\"" }{TEXT -1 29 " we use the following command" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "A[-3]:=5;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 24 "We can assign the value " }{XPPEDIT 18 0 "i^2;" "6#*$%\"iG\"\"#" }{TEXT -1 4 " to " } {XPPEDIT 18 0 "A[i];" "6#&%\"AG6#%\"iG" }{TEXT -1 31 " for i from -3 t o 4 as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "for i fr om -3 to 4 do \n A[i]:=i^2; \nend do;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "Note that you cannot use other values for the index of A: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "A[5]:=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "A[-4];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 89 "Note that unlike regular variable one cannot see the valu e of A by the following command:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "Use eval(A) to see the value of the entries of A, as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 66 "You may prefer the following way to see what the array A contai ns:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "seq(A[i],i=-3..4);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 82 "Now we define a 2-dimentional a rray B. Again we must specify the range of indices." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "B:=array(-1..2,0..1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "Here we assign values to the array:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 78 "for i from -1 to 2 do \n for j fro m 0 to 1 do \n B[i,j]:=i + j*x;\n end do;\n" }{MPLTEXT 1 0 7 "end \+ do;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 65 "Observe the following whic h is similar to the 1-dimensional case:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "B;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(B );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 54 "We can see the value of a p articular entry as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "B[-1,0]; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 47 "We can change thi s by the following assignment:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "B[-1,0]:=110;" }}}{PARA 0 "" 0 "" {TEXT -1 2 "A " }{TEXT 263 6 "matrix" }{TEXT -1 250 " is a 2-dimensional array where the row and \+ column indices start with 1. One can define matrices directly or conve rt a 2-dimensional array into a matrix as in the following command. Re call that B was defined as an array with indices -1..2 and 0..1 . " }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "MB:=convert(B,matrix);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 55 "Note that the indices in MB run fr om 1 to 4 and 1 to 2." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "B[ -1,0],B[-1,1]; \nMB[1,1],MB[1,2];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 125 "Maple displays the contents of a matrix in an easier to read form than for arrays. But note that the following gives nothing." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "MB;" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 52 "We must use the following to see the contents of MB." } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "evalm(MB);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 25 "C onsider another example:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "C:=array(1..4,1..2);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 76 "fo r i from 1 to 4 do\nfor j from 1 to 2 do\n C[i,j]:=(i-2)+(j-1)*x; \ne nd do;\n" }{MPLTEXT 1 0 8 "end do;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "evalm( C);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 111 "We can ask Maple if B is \+ a matrix or an array as follows. Note that all matrices are arrays but not vice versa." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "type(B, matrix);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "type(B,array) ;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "type(MB, matrix);" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "type(C,matrix);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 116 "There are other ways to form a ma trix or array. Consider the following examples. We first construct a l ist of lists:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "L:=[[1,2], [0,1],[1,2],[4,5]];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 132 "Note that the following all give the same result, namely, a 4 by 2 matrix with \+ rows taken from L. Study these assignments carefully." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "X:=array(1..4,1..2, L);\nY:=array(L );\nZ:=matrix(L);\nW:=matrix(4,2,[1,2,0,1,1,2,4,5]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "type(X,matrix), type(Y,matrix), type(Z,ma trix), type(W,matrix);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 88 "If you \+ just specify the dimensions of the matrix you may treat the entries as variables." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "H:=matrix(2, 2);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "H;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "H=evalm(H);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 77 "By loading the old linalg package we can find the determi nant of this matrix." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "wit h(linalg):\ndet(H);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 86 "To change \+ one of the entries uses an assignment statement as in the following ex ample:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "H[1,2]:=10000;\nH =evalm(H);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 120 "One could define d -dimensional arrays for d > 2, but they are not much used. Here's an e xample of a 3-dimensional array:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 92 "T:=array(1..3,1..4,1..5):\nfor i from 1 to 3 do\n for j from 1 to 4 do\n for k from 1 to 5 do\n" }{MPLTEXT 1 0 45 " T[i, j,k]:=i+j*x+k*x^2;\n end do:\n end do:\n" }{MPLTEXT 1 0 7 "end do:" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "T[3,4,5];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 7 " Tables" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 28 "We now discuss the datatype " }{TEXT 264 5 "table" } {TEXT -1 36 ". Tables are similar to arrays, but " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 222 "" 0 "" {TEXT 201 32 "the indices need not b e integers" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 201 5 " and " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 265 56 "one need not declare that a variable represents a table." } {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 220 "If you make an assignment of the form G[z]:=w, then Mapl e creates a table with the entry z=w. It is not necessary to declare \+ that G is a table. Then you may add to this table at will. You may al so use tables to create " }{TEXT 266 17 "indexed variables" }{TEXT -1 193 ". In fact indexed variables are the same as tables. We illustrat e by creating a table named G. The indices are z, box, cup, 1, 2, 3. T he entries are w, coin, wine, and some three element sets:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 82 "G[z]:=w;\nG[box]:=coin;\nG[cup]:=wine;\nfor i from \+ 1 to 3 do G[i]:=\{0,i,i+1\}; end do;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "G[z], G[box], G[cup], G[1], G[2], G[3];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 39 "Here's how you can get a list of the i" }{TEXT 267 7 "ndices " }{TEXT -1 29 "of a table and a list of the " } {TEXT 268 7 "entries" }{TEXT -1 84 " in the table. Note that the indic es and entries are exhibited as one element lists." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "indices(G);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "entries(G);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 83 "A s for arrays and matrices the following does not return the contents o f the table:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "G;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 84 "If you look carefully at the outpu t of eval(G), you can see what the equations mean." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(G);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "type(G,table);\ntype(G,array);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "Recall that " }{TEXT 269 3 "cat" }{TEXT -1 146 " is \+ the concatenation operator, for example, we have (after unassigning i \+ which now has the value of 4 due to the execution of the above do loop ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "i:='i':" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "MyName:=cat(P,e,t,e,r); " }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 7 "We use " }{TEXT 270 3 "cat" }{TEXT -1 37 " to add some entries to the table G. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "for x in \{p,q,r\} do G[x]:=cat(x,stuff); end do ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(G);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "G[r];\nG[box];" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 8 "One can " }{TEXT 271 6 "change" }{TEXT -1 51 " the \+ entries in a table by simply reassigning them:" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 28 "G[1]:=G[1] union \{infinity\};" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 8 "One can " }{TEXT 272 6 "delete" }{TEXT -1 54 " indices and entries as in the following two examples." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "G[1];\nG[1]:=evaln(G[1]);\nG[1];" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "indices(G);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "G[2];\nG[2]:='G[2]';\nG[2];" }} {PARA 0 "" 0 "" {TEXT -1 42 " \+ " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "indices(G);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 16 "No te that we do " }{TEXT 273 3 "not" }{TEXT -1 157 " have to declare bef ore hand that a variable is going to represent a table. However, we mu st do so for arrays and matrices: Consider the following examples:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "type(Z,table), type(Z,array);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "for i from 1 to 2 do\nfor j from 1 \+ to 2 do\nZ[i,j]:=i+j;\nend do;\n" }{MPLTEXT 1 0 7 "end do;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "type(Z,table), type(Z,array);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(Z);" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 57 "But look what happens if we first say that Z is an array:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 72 "restart:\nZ:=arr ay(1..2,1..2);\nfor i from 1 to 2 do\nfor j from 1 to 2 do\n" } {MPLTEXT 1 0 28 "Z[i,j]:=i+j;\nend do;\nend do;" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 44 "type(Z,table),type(Z,array), type(Z,matrix);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "eval(Z);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 21 "1-dimensional arrays " }{TEXT 274 2 "vs" }{TEXT -1 6 " lists" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 204 "Here we discuss some differences \+ between lists and 1-dimensional arrays. Of course if we want indices o ther than 1 to some positive integer n we must use arrays or tables. B ut there are other differences." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 54 "(This section was largely copied from Rob ert Israel's " }{TEXT 275 5 "Maple" }{TEXT -1 1 " " }{TEXT 276 7 "Advi sor" }{TEXT -1 1 " " }{TEXT 277 20 "Database for Maple 6" }{TEXT -1 3 ".) " }}{PARA 0 "" 0 "" {TEXT -1 120 "\nMaple allow you to change a li st by assigning a new value to one of its components provided the list is not too long: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "resta rt;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "L:=[a,b,c,d,e]; \nL[ 2]:=Changed; \nL;" }}}{PARA 0 "" 0 "" {TEXT -1 146 "However, it only w orks for lists of length 100 or less. Trying it for a longer list pro duces an error message as we see in the following example." }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 46 "restart:\nL:=[seq(i,i=10..111)]:\nL [2]:=Changed;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 78 "Nevertheless, th e same effect can be obtained for a list of any length, using " } {TEXT 278 6 "subsop" }{TEXT -1 1 ":" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "L:=subsop(2=Changed,L);" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "For arrays the usual assignment works." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 59 "restart:\nL:=array(1..101,[seq(i,i=1..101 )]):\nL[2]:=Changed;" }}}{PARA 0 "" 0 "" {TEXT -1 339 "Assignment to a list is rather inefficient if the list is long, because it requires c opying the whole list structure. If you used an array it would be ve ry quick. Nevertheless, if only a few of these operations are to be d one, it may still be preferable to use lists rather than arrays, becau se lists can be produced very quickly using " }{TEXT 279 3 "seq" } {TEXT -1 189 ". It takes longer to set up the array, but as a trade o ff it is easier to access the entries. See Israel's Maple Advisor Data base for Maple 6 for some timed experiments to illustrate this." }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "a:=array(-1..19,[seq(i^2,i=1 ..20)]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "a[0];" }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 37 " Functions, tables, type and what type" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 40 "We have already seen three ways to make " }{TEXT 280 9 "functions" }{TEXT -1 44 " from expressio ns. Here we show another way:" }}{PARA 201 "" 0 "" {TEXT 201 13 "First we can " }{TEXT -1 22 "assign values at will " }{TEXT 201 60 "as foll ows: We make up a couple of functions called f and g." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 53 "f(x):=y; f(y):=z; f(z):=x;\ng(x):=y; g(y):=x; g(z): =z;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "f(x),f(y),f(z),g(x), g(y),g(z);" }}}{EXCHG {PARA 209 "" 0 "" {TEXT -1 82 "This explains why f(x):=x^2+1; does not define f. Actually it defines the function" }} {PARA 0 "" 0 "" {TEXT 281 64 "f at the variable x only, but not for an ything different from x." }{TEXT -1 13 " For example:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "h(x):=x^2+x+1;" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 5 "h(x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "h(y);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "This indicates th at we have not yet defined h at the value y." }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 282 24 "Composition of functions" }{TEXT -1 53 " in Maple is given by @: For example, the co mposition" }}{PARA 0 "" 0 "" {TEXT -1 81 "of f and g as defined above \+ is f@g. Also the composition of f with itself n times" }}{PARA 0 "" 0 "" {TEXT -1 17 "is given by f@@n:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "(f@g)(x),f(g(x)); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 52 "Note that we must write (f@g)(x) rather than f@g(x)." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "(f@@3)(x),f(f(f(x)));" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 201 15 "Second, we can " }{TEXT -1 33 " change the value of any function " }{TEXT 201 34 "whether we made it, \+ or it is built" }}{PARA 0 "" 0 "" {TEXT -1 55 "into Maple: (Not someth ing to do lightly.) For example:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "sin(0):=3;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "sin(0);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart;\n" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "sin(0);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 283 9 "func tions" }{TEXT -1 8 " versus " }{TEXT 284 6 "tables" }{TEXT -1 27 ": \n \nExpression of the form " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT 285 43 " name(variable)" } {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 12 "are of type " }{TEXT 286 8 "function" }{TEXT -1 50 ". On \+ the other hand if your execute the statement " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 287 51 " \+ name[variable]:=value;" }{TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 16 "then Maple give " }{TEXT 288 4 "name" }{TEXT -1 10 " the type " }{TEXT 289 5 "table" }{TEXT -1 2 ". \+ " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 39 "This \+ gives us the peculiar result that " }{TEXT 290 6 "sin(x)" }{TEXT -1 12 " is of type " }{TEXT 291 9 "function " }{TEXT 201 8 "in Maple" } {TEXT -1 6 ", but " }{TEXT 292 3 "sin" }{TEXT -1 4 " is " }{TEXT 293 4 "not " }{TEXT 201 8 "of type" }{TEXT 294 11 " function " }{TEXT 201 8 "in Maple" }{TEXT 295 1 "." }{TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 296 9 "NOTE WELL" }{TEXT -1 107 ": This usage deviates from the usual mathematical meaning of function . In ordinary mathematics we say that " }{TEXT 297 3 "sin" }{TEXT -1 19 " is a function and " }{TEXT 298 6 "sin(x)" }{TEXT -1 17 " is the v alue of " }{TEXT 299 3 "sin" }{TEXT -1 4 " at " }{TEXT 300 1 "x" } {TEXT -1 325 ". In certain constructions, for example when solving rec urrences and differential equations, one is required to use the Maple \+ notion of a function. The reason is that in these cases Maple needs to know what the independent variable is.\n\nTo make matters even more c onfusing some computer languages refer to what Maple calls a " }{TEXT 301 9 "procedure" }{TEXT -1 13 " by the name " }{TEXT 302 8 "function " }{TEXT -1 18 ". \n\nSo to repeat: " }{TEXT 303 10 "procedures" } {TEXT -1 14 " in Maple are " }{TEXT 304 9 "functions" }{TEXT -1 65 " i n the usual mathematical sense of the word, but NOT as a Maple " } {TEXT 305 4 "type" }{TEXT -1 60 ". The following examples may help to \+ clarify this confusion:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 " restart;\ntype(f(x),function);\n\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "type(sin,function);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "type(sin(x),function);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "type(sin,procedure);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "type(g,table);\ng[x]:=y;\ntype(g,table);" }}{PARA 11 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 306 8 "whattype " }{TEXT -1 52 " will give the type, but sometimes one needs to use " }{TEXT 307 4 "eval" }{TEXT -1 33 " first, as in the examples below:" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "whattype(sin);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "whattype(eval(sin));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "g[3]:=3: \nwhattype(g);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "whattype(eval(g));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "whattype(f(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "whattype(.34);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 14 "whattype(3/4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "whattype(-3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "whattype(3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "typ e(3,posint);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "whattype((x +z)*(y+3));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "whattype(x^2 );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 50 "To see the enormous number \+ of Maple types execute:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "? type" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{PARA 204 "" 0 "" {TEXT -1 0 "" }{TEXT 201 8 "- End - " }}}{MARK "11" 0 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 1 1 2 33 1 1 }